package com.bite.demo.config;

import com.bite.demo.enums.ResultCodeEnum;
import com.bite.demo.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class ExceptionAdvice {
    @ExceptionHandler
    public Result handler(Exception e) {
        log.error("发送异常，e:"+e);
        return Result.fail(e.getMessage());
    }
    @ExceptionHandler
    public Result handler(UnsupportedOperationException e) {
        log.error("发送异常，e:"+e);
        return Result.fail(ResultCodeEnum.PARAM_INVAILD.getCode(),e.getMessage());
    }

    @ExceptionHandler
    public Result handler(MethodArgumentNotValidException e) {
        log.error("参数校验不通过，e:"+e.getMessage());
        return Result.fail(ResultCodeEnum.PARAM_INVAILD.getCode(),e.getMessage());
    }

}
